Skip to content

chore(repo): Clean up machine integration tests#8214

Merged
wobsoriano merged 2 commits intomainfrom
rob/machine-auth-e2e-cleanup
Mar 31, 2026
Merged

chore(repo): Clean up machine integration tests#8214
wobsoriano merged 2 commits intomainfrom
rob/machine-auth-e2e-cleanup

Conversation

@wobsoriano
Copy link
Copy Markdown
Member

@wobsoriano wobsoriano commented Mar 31, 2026

Description

Refactors the machine integration tests to use shared Playwright helpers instead of duplicating the same auth contract across framework-specific files.

This moves the repeated API key, M2M, and OAuth machine test scenarios into integration/testUtils/machineAuthHelpers.ts and reduces the framework test files to thin adapters that only define route wiring and endpoint paths.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Tests
    • Consolidated machine authentication test infrastructure and utilities for improved maintainability and reduced duplication across test suites.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

⚠️ No Changeset found

Latest commit: 546e62e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 31, 2026 5:46pm

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 31, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@8214

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8214

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8214

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8214

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8214

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8214

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8214

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8214

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8214

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8214

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8214

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8214

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8214

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8214

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8214

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8214

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8214

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8214

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8214

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8214

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8214

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8214

commit: 546e62e

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

This PR consolidates machine authentication test infrastructure by refactoring machine auth utilities and test registration. The changes migrate test implementations from machineAuthService.ts to a new machineAuthHelpers.ts file, which introduces a MachineAuthTestAdapter abstraction and three test registration functions (registerApiKeyAuthTests, registerM2MAuthTests, registerOAuthAuthTests). These helpers encapsulate shared setup, provisioning, assertion logic, and cleanup for API key, M2M token, and OAuth authentication scenarios. The inline Playwright test suites in four framework-specific test files (Astro, Next.js, React Router, and TanStack Start) are replaced with delegated calls to these shared registration functions, eliminating test code duplication while centralizing test behavior.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: consolidating machine integration tests from multiple test files into shared helper functions and utilities.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@integration/testUtils/createTestUtils.ts`:
- Around line 23-32: The exported signature for createTestUtils is unsound:
change it to explicit overloads (one overload for Params that includes
page/useTestingToken returning FullReturn and another for Params without page
returning OnlyAppReturn) instead of the current conditional return type; remove
generic defaults that reference body locals (drop/replace Services = typeof
services, PO = typeof pageObjects, BH = typeof browserHelpers) and either accept
plain generics without those defaults or infer types from exported module-level
types, and eliminate the runtime "as any" casts by narrowing the return with a
runtime check on params.page so the implementation returns the correct typed
shape (use the overloads to guide callers and keep internal variables services,
pageObjects, browserHelpers as implementation details).

In `@integration/testUtils/machineAuthHelpers.ts`:
- Around line 184-198: The createMachineClient and createOAuthClient functions
currently return raw Clerk clients and must be wrapped with the retry proxy from
integration/testUtils/retryableClerkClient.ts; update both functions to import
and use the retry wrapper (e.g., withRetry or the exported retryable client
factory) so they return the retry-wrapped client instance instead of the direct
createClerkClient(...) result, ensuring provisioning/cleanup in
beforeAll/afterAll get 429/502/503/504 backoff behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: e5f82168-7e00-4ff5-bb84-7b76d3ef86eb

📥 Commits

Reviewing files that changed from the base of the PR and between c50e887 and 74d109c.

📒 Files selected for processing (8)
  • integration/testUtils/createTestUtils.ts
  • integration/testUtils/index.ts
  • integration/testUtils/machineAuthHelpers.ts
  • integration/testUtils/machineAuthService.ts
  • integration/tests/astro/machine.test.ts
  • integration/tests/next-machine.test.ts
  • integration/tests/react-router/machine.test.ts
  • integration/tests/tanstack-start/machine.test.ts
💤 Files with no reviewable changes (1)
  • integration/testUtils/machineAuthService.ts

Comment on lines +184 to +198
const createMachineClient = () =>
createClerkClient({
secretKey: instanceKeys.get('with-api-keys').sk,
});

const buildApp = async (adapter: MachineAuthTestAdapter, addRoutes: RouteBuilder): Promise<Application> => {
const config = addRoutes(adapter.baseConfig.clone());
return config.commit();
};

const createOAuthClient = (app: Application) =>
createClerkClient({
secretKey: app.env.privateVariables.get('CLERK_SECRET_KEY'),
publishableKey: app.env.publicVariables.get('CLERK_PUBLISHABLE_KEY'),
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Wrap these direct Clerk clients with the retry proxy.

createMachineClient() and createOAuthClient() bypass withRetry, so the machine/OAuth provisioning and cleanup in this file loses the 429/502/503/504 backoff that integration/testUtils/retryableClerkClient.ts:1-92 provides. These calls run in beforeAll/afterAll, so one transient Clerk API failure will fail the whole suite.

🐛 Proposed fix
+import { withRetry } from './retryableClerkClient';
+
 const createMachineClient = () =>
-  createClerkClient({
-    secretKey: instanceKeys.get('with-api-keys').sk,
-  });
+  withRetry(
+    createClerkClient({
+      secretKey: instanceKeys.get('with-api-keys').sk,
+    }),
+  );
@@
 const createOAuthClient = (app: Application) =>
-  createClerkClient({
-    secretKey: app.env.privateVariables.get('CLERK_SECRET_KEY'),
-    publishableKey: app.env.publicVariables.get('CLERK_PUBLISHABLE_KEY'),
-  });
+  withRetry(
+    createClerkClient({
+      secretKey: app.env.privateVariables.get('CLERK_SECRET_KEY'),
+      publishableKey: app.env.publicVariables.get('CLERK_PUBLISHABLE_KEY'),
+    }),
+  );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@integration/testUtils/machineAuthHelpers.ts` around lines 184 - 198, The
createMachineClient and createOAuthClient functions currently return raw Clerk
clients and must be wrapped with the retry proxy from
integration/testUtils/retryableClerkClient.ts; update both functions to import
and use the retry wrapper (e.g., withRetry or the exported retryable client
factory) so they return the retry-wrapped client instance instead of the direct
createClerkClient(...) result, ensuring provisioning/cleanup in
beforeAll/afterAll get 429/502/503/504 backoff behavior.

@wobsoriano wobsoriano merged commit 1261d8e into main Mar 31, 2026
65 of 76 checks passed
@wobsoriano wobsoriano deleted the rob/machine-auth-e2e-cleanup branch March 31, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants